package com.yiyi.user.service.impl;

import com.yiyi.common.utils.DateUtils;
import com.yiyi.user.domain.CustomerInfo;
import com.yiyi.user.domain.OrderInfo;
import com.yiyi.user.mapper.CustomerInfoMapper;
import com.yiyi.user.mapper.OrderInfoMapper;
import com.yiyi.user.service.ICustomerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 客户管理Service业务层处理
 *
 * @author yiyi
 * @date 2024-09-24
 */
@Service
public class CustomerInfoServiceImpl implements ICustomerInfoService
{
    @Autowired
    private CustomerInfoMapper customerInfoMapper;
    @Autowired
    private OrderInfoMapper orderInfoMapper;



    /**
     * 查询客户管理
     *
     * @param id 客户管理主键
     * @return 客户管理
     */
    @Override
    public CustomerInfo selectCustomerInfoById(Long id)
    {
        return customerInfoMapper.selectCustomerInfoById(id);
    }

    /**
     * 根据订单编号获取 客户信息
     * @param customerInfo
     * @return
     */
    @Override
    public CustomerInfo getCustomerInfoByOrderNum(CustomerInfo customerInfo) {
        return customerInfoMapper.getCustomerInfoByOrderNum(customerInfo);
    }

    /**
     * 查询客户管理列表
     *
     * @param customerInfo 客户管理
     * @return 客户管理
     */
    @Override
    public List<CustomerInfo> selectCustomerInfoList(CustomerInfo customerInfo)
    {
        return customerInfoMapper.selectCustomerInfoList(customerInfo);
    }

    /**
     * 新增客户管理
     *
     * @param customerInfo 客户管理
     * @return 结果
     */
    @Override
    public int insertCustomerInfo(CustomerInfo customerInfo)
    {
        //customerInfo.setCreateBy(SecurityUtils.getUsername());
        customerInfo.setCreateTime(DateUtils.getNowDate());
        return customerInfoMapper.insertCustomerInfo(customerInfo);
    }

    /**
     * 修改客户管理
     *
     * @param customerInfo 客户管理
     * @return 结果
     */
    @Override
    public int updateCustomerInfo(CustomerInfo customerInfo)
    {
        customerInfo.setUpdateTime(DateUtils.getNowDate());
        return customerInfoMapper.updateCustomerInfo(customerInfo);
    }

    /**
     * 批量删除客户管理
     *
     * @param ids 需要删除的客户管理主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoByIds(Long[] ids)
    {
        return customerInfoMapper.deleteCustomerInfoByIds(ids);
    }

    /**
     * 删除客户管理信息
     *
     * @param id 客户管理主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoById(Long id)
    {
        return customerInfoMapper.deleteCustomerInfoById(id);
    }

    /**
     * 修改信息
     */
    @Override
    @Transactional
    public boolean updateInfo(CustomerInfo customerInfo)
    {
        boolean result=true;
        OrderInfo orderInfo=new OrderInfo();
        orderInfo.setPayStatus("1");
        customerInfo.setUpdateTime(DateUtils.getNowDate());
        try {
            customerInfoMapper.updateCustomerInfo(customerInfo);
            orderInfoMapper.updateOrder(orderInfo);
        }catch (Exception e){
            result=false;
        }
        return result;
    }
}
